package com.qgs.waf.jedis;

import java.util.Set;

import org.springframework.data.redis.core.ZSetOperations.TypedTuple;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class JedisUtil {
	public static String tupleSets2Json(Set<TypedTuple> tuples, boolean withScore) {
		JsonArray json = null;
		if (null != tuples) {
			json = new JsonArray();
			for (TypedTuple<String> tuple : tuples) {
				JsonObject element = new JsonObject();
				if (withScore) {
					element.addProperty("score", tuple.getScore());
					element.addProperty("value", tuple.getValue());
					json.add(element);
				} else {
					json.add(tuple.getValue());
				}
			}
		} else {
		}
		return (null == json) ? "" : json.toString();
	}
}
